/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package DAO;
import DTO.CFields;
import DTO.CLoai_KhuyenMai;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

public class CLoai_KhuyenMaiDAO extends IData<CLoai_KhuyenMai>{

    @Override
    public CLoai_KhuyenMai add(CLoai_KhuyenMai item) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    protected void add(CLoai_KhuyenMai item, int t) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void saveBatch() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int addrows(List<CLoai_KhuyenMai> list, SubConfig config) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public CLoai_KhuyenMai Find(CLoai_KhuyenMai item, List<CLoai_KhuyenMai> list) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    protected Object OnSubmit(CLoai_KhuyenMai item, int t, SubConfig config) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public Object insertOnSubmit(CLoai_KhuyenMai item, SubConfig config) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public Object updateOnSubmint(CLoai_KhuyenMai item, SubConfig config) {
          String mysql = "update " + CFields.tb_loai_khuyen_mai + " set " + CFields.active 
                + "=?"  + " where " + CFields.id + "=?" ;
        Object result = 0;
        try {
            PreparedStatement cs = config.connec.prepareStatement(mysql);
            cs.setBoolean(1, item.getActive());
            cs.setLong(2, item.getId());
            result = cs.executeUpdate();            
        } catch (SQLException ex) {
            Logger.getLogger(CLoai_KhuyenMaiDAO.class.getName()).log(Level.SEVERE, null, ex);
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }        
        return result;
    }

    @Override
    public Object deleteOnSubmint(CLoai_KhuyenMai item, SubConfig config) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    protected CLoai_KhuyenMai getItem(ResultSet rs) {
        CLoai_KhuyenMai item = new CLoai_KhuyenMai();
        try {
            item.setActive(rs.getBoolean(CFields.active));
            item.setHinhThucKM(rs.getString(CFields.hinh_thuc_km));
            item.setId(rs.getLong(CFields.id));
        } catch (SQLException ex) {
            Logger.getLogger(CLoai_KhuyenMaiDAO.class.getName()).log(Level.SEVERE, null, ex);
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
        return item;
    }

    @Override
    public List<CLoai_KhuyenMai> getAll(SubConfig config) {
         String mysql = "select * from " + CFields.tb_loai_khuyen_mai + " " + this.sWhere;
        return this.getAll(mysql, config);
    }

   
    
}
